package com.woniuxy.web;

import com.woniuxy.entity.Region;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.ResponseState;
import com.woniuxy.service.RegionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Controller
@RequestMapping("region")
public class RegionController {
    @Autowired
    private RegionService regionService;

   /* @RequestMapping("list/{pid}")
    @ResponseBody
    public ResponseEntity show(@PathVariable int pid){
        List<Region> regions = regionService.getAll(pid);
        return new ResponseEntity<List<Region>>(regions);
    }*/

    @PostMapping("getProvinces")
    @ResponseBody
    public ResponseEntity getProvinces(Region region){
        ResponseEntity responseEntity = new ResponseEntity();
        List<Region> regions = regionService.getAll(region);
        responseEntity.setCode(ResponseState.SUCCESS);
        responseEntity.setData(regions);
        return responseEntity;
    }

    @PostMapping("getCitys")
    @ResponseBody
    public ResponseEntity getCitys(@RequestBody Region region) {
        ResponseEntity responseEntity = new ResponseEntity();
        List<Region> regions = regionService.getAll(region);
        responseEntity.setCode(ResponseState.SUCCESS);
        responseEntity.setData(regions);
        return responseEntity;
    }

    @PostMapping("getDistrict")
    @ResponseBody
    public ResponseEntity getDistrict(@RequestBody Region region) {
        ResponseEntity responseEntity = new ResponseEntity();
        List<Region> regions = regionService.getAll(region);
        responseEntity.setCode(ResponseState.SUCCESS);
        responseEntity.setData(regions);
        return responseEntity;
    }
}